from django.shortcuts import render
from .models import *
from django.core.paginator import Paginator
from utils.wrapper import *



def all(request,param):
    try:
        title = StoryType.objects.get_name_by_id(param)
        all_stories = Story.objects.get_story_by_type(param)
    except:
        pass
    # 创建分页器
    paginator = Paginator(all_stories, 8)
    # 获取当前页码
    page_now = get(request, "page", "1")
    # 当前页面文章
    stories = paginator.page(page_now)
    return render(request,"story/all.html",locals())

def one(request,param):
    try:
        story = Story.objects.get_story_by_id(get(request,"id"))
        # 获取最新两个文章推荐
        new_stories_2 = Story.objects.get_story_by_type(param)[:2]
    except:
        pass
    return render(request,"story/one.html",locals())